<template>
  <div>
    <van-nav-bar title="城市选择" left-arrow @click-left="onClickLeft" />
    <div v-for="item in cityList" :key="item.prefix" class="item">
      <div class="title">{{ item.prefix }}</div>
      <ul>
        <li
          v-for="value in item.cities"
          :key="value.cityId"
          class="cityli"
          @click="choosecity(value)"
        >
          {{ value.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getCitiesApi } from "../../../utils/seeDoctorUtils/api";
export default {
  data() {
    return {
      cityList: [],
    };
  },
  mounted() {
    this.getCityList();
  },
  methods: {
    async getCityList() {
      const res = await getCitiesApi();
      console.log(res);
      this.cityList = res.result;
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    choosecity(value) {
      // this.$router.push("/home/seeDoctor/" + value.name);
      this.$router.go(-1);
      localStorage.setItem("city", value.name);
    },
  },
};
</script>

<style lang="less" scoped>
.title {
  padding-left: 25px;
  line-height: 30px;
  background: #ebebeb;
}
.cityli {
  height: 44px;
  line-height: 44px;
  margin-left: 15px;
  border-bottom: 1px solid #c8c7cc;
  font-size: 12px;
  &:last-child {
    border: none;
  }
}
.item:first-child li {
  float: left;
  background: #fff;
  width: 29%;
  height: 33px;
  margin-top: 15px;
  margin-left: 4%;
  padding: 0 4px;
  border: 1px solid #e6e6e6;
  border-radius: 3px;
  line-height: 33px;
  text-align: center;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
